import axios from 'axios'
import Vue from 'vue'

// base function
const httpGet = (url, params) => axios.get('/api' + url, { params: params })
const httpPost = (url, data) => axios.post('/api' + url, data)
const httpPut = (url, data) => axios.put('/api' + url, data)
const httpDelete = (url, data) => axios.delete('/api' + url, { data: data })

// RestFUL style
// const get = (url, id) => httpGet(url + "/" + id, null)
// const list = (url, params) => httpGet(url, params)
// const add = (url, data) => httpPost(url, data)
// const edit = (url, id, data)=> httpPut(url + "/" + id, data)
// const remove = (url, id)=> httpDelete(url + "/" + id, null)

let funcs = {}

/**
 * 登录
 */
funcs.login = (params) => httpPost('/user/login', params)
/**
 * 基础数据
 */
funcs.listBasicData = (dataType) => httpGet('/basicData/list/' + dataType)
funcs.listCategoriesForTips = () => httpGet('/detectCategory/listAllDetectCategoryName')
funcs.listBatchesForTips = (keyword) => httpPost('/sample/batchSnComplete', {keyword: keyword})
funcs.listsamplesForTips = (keyword) => httpPost('/sample/sampleSnComplete', {keyword: keyword})
/**
 * 任务下达
 */
funcs.createTask = (params) => httpPost('/task/createTask', params)
funcs.detectUserByDetectItemId = (params) => httpGet('/relationship/detectUser/DetectItemId/' + params)
funcs.checkUserByDetectItemId = (params) => httpGet('/relationship/checkUser/DetectItemId/' + params)
funcs.listByDetectItemId = (params) => httpGet('/detectMethod/list/detectItemId/' + params)
funcs.getdetectAllInfo = (params) => httpGet('/sample/detectAllInfo/' + params)
/**
 * 样品管理
 */
funcs.addSamples = (params) => httpPost('/sample/saveSamples', params)
funcs.listSamplesByContract = (contractSn) => httpPost('/sample/listByContract', {contractSn: contractSn})
funcs.listDetectStardardByDetectCategoryId = (detectCatrgoryId) => httpGet('/detectStandard//listForEdit/' + detectCatrgoryId)
funcs.setDetectItems = (params) => httpPost('/contract/setBatchOfferItems', params)
funcs.listCompany = (keyword) => httpPost('/contract/getCompanyName', {keyword: keyword})
funcs.getCompanyByID = (keyword) => httpPost('/contract/company/' + keyword)
funcs.saveContract = (params) => httpPost('/contract/save/', params)
funcs.exportContract = () => httpGet('/contract/export')
funcs.searchSample = (params) => httpPost('/sample/search', params)
funcs.getSampleByID = (dataType) => httpGet('/sample/detail/' + dataType)
/**
 * 批次查询
 */
funcs.CheckSample = (params) => httpGet('/sample/listByBatch/' + params)
/**
 * 任务管理
 */
funcs.TeskList = (params) => httpGet('/sample/detail' + params)
funcs.TeskDispatch = (params) => httpPost('/sample/dispatch', params)
/**
 * 系统管理
 */
funcs.detectStandard = (params) => httpGet('/detectStandard/detail' + params)
funcs.systemLog = (params) => httpPost('/systemLog/list', params)
/**
 * 角色管理
 */
funcs.RoleMsg = () => httpPost('/role/list/')
funcs.createRole = (params) => httpGet('/role/create/' + params)
funcs.editRole = (params) => httpGet('/role/update/' + params)
funcs.listRole = () => httpGet('/role/operations/')
funcs.deleteRol = (params) => httpGet('/role/delete/' + params)
/**
 * 个人设置
 */
funcs.getCurrentLoginUser = (params) => httpGet('/user/getCurrentLoginUser', params)
funcs.updateUser = (params) => httpPost('/user/update/', params)
funcs.updatePwd = (params) => httpPost('/user/updatePassword/', params)
funcs.DetectItem = () => httpGet('/detectMethod/relationlist')

console.log(funcs)

export default funcs
